package com.ruoyi.project.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.system.domain.SysOrder;
import com.ruoyi.project.system.mapper.SysOrderMapper;
import com.ruoyi.project.system.service.ISysOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 订单Service业务层处理
 *
 * @author orange
 * @date 2022-04-08
 */
@Service
public class SysOrderServiceImpl implements ISysOrderService {
  @Autowired private SysOrderMapper sysOrderMapper;

  /**
   * 查询订单
   *
   * @param orderId 订单主键
   * @return 订单
   */
  @Override
  public SysOrder selectSysOrderByOrderId(Long orderId) {
    return sysOrderMapper.selectSysOrderByOrderId(orderId);
  }

  /**
   * 查询订单列表
   *
   * @param sysOrder 订单
   * @return 订单
   */
  @Override
  public List<SysOrder> selectSysOrderList(SysOrder sysOrder) {
    return sysOrderMapper.selectSysOrderList(sysOrder);
  }

  /**
   * 新增订单
   *
   * @param sysOrder 订单
   * @return 结果
   */
  @Override
  public int insertSysOrder(SysOrder sysOrder) {
    sysOrder.setCreateTime(DateUtils.getNowDate());
    return sysOrderMapper.insertSysOrder(sysOrder);
  }

  /**
   * 修改订单
   *
   * @param sysOrder 订单
   * @return 结果
   */
  @Override
  public int updateSysOrder(SysOrder sysOrder) {
    sysOrder.setUpdateTime(DateUtils.getNowDate());
    return sysOrderMapper.updateSysOrder(sysOrder);
  }

  /**
   * 批量删除订单
   *
   * @param orderIds 需要删除的订单主键
   * @return 结果
   */
  @Override
  public int deleteSysOrderByOrderIds(Long[] orderIds) {
    return sysOrderMapper.deleteSysOrderByOrderIds(orderIds);
  }

  /**
   * 删除订单信息
   *
   * @param orderId 订单主键
   * @return 结果
   */
  @Override
  public int deleteSysOrderByOrderId(Long orderId) {
    return sysOrderMapper.deleteSysOrderByOrderId(orderId);
  }

  @Override
  public int acceptOrder(Long orderId) {

    SysOrder sysOrder = new SysOrder();
    sysOrder.setOrderId(orderId);
    sysOrder.setOrderStatus(3L);
    sysOrder.setUpdateTime(new Date());
    return sysOrderMapper.updateSysOrder(sysOrder);
  }
}
